package com.hongye.broker.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hongye.broker.service.RentHouseService;
import com.hongye.broker.vo.HouseSelectVo;
import com.hongye.common.entity.RentHouseEntity;
import com.hongye.common.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.hongye.broker.vo.HouseSelectVo;
import org.springframework.web.bind.annotation.RequestBody;

/*
* 出租房
* */
@RestController
@RequestMapping("/rentHouse")
public class RentHouseController {
    @Autowired
    private RentHouseService rentHouseService;

    @RequestMapping("/rentList")
    public List<RentHouseEntity> list(){
        return rentHouseService.rentList();
    }
    //总结一下可能引发内存溢出的几点原因：
    //　　1.内存中加载的数据量过于庞大，如一次从数据库取出过多数据，需手动垃圾回收；
    //　　2.集合类中有对对象的引用，使用完后未清空，使得JVM不能回收；
    //　　3.代码中存在死循环或循环产生过多重复的对象实体；
    //　　4.使用的第三方软件中的BUG；
    //　　5.启动参数内存值设定的过小；

    @RequestMapping("/update")
    public ResponseResult updateHouse(@RequestBody RentHouseEntity rentHouseEntity){
        rentHouseEntity.setEsStatus(1);
        rentHouseService.updateHouse(rentHouseEntity);
        return new ResponseResult(1,"修改成功");
    }

    //租房成交
    @RequestMapping("/zu")
    public ResponseResult maifang(Integer page,Integer size,String rentHouseTitle) {
        IPage<RentHouseEntity> list = rentHouseService.zu(page, size, rentHouseTitle);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        return new ResponseResult(200, "租房成交", map);
    }

    /*
     * 新房接口
     * */
    @RequestMapping("/list")
    public ResponseResult list(@RequestBody HouseSelectVo houseSelectVo){
        ResponseResult responseResult = rentHouseService.list(houseSelectVo);
        return responseResult;
    }
}
